<meta name="csrf-token" content="{{ csrf_token() }}">
<style>
    #chart_container div {
        font-family: "微软雅黑";
        font-size: 25px;
    }

    textarea {
        overflow:hidden;
        font-size: 18px;
    }
</style>
<div id="page-wrapper">
    <script src="{{URL::asset('js/echarts.js')}}"></script>
    <script src="{{URL::asset('js/customed.js')}}"></script>
    <script src="{{URL::asset('js/jspdf.min.js')}}"></script>
    <script src="{{URL::asset('js/html2canvas.js')}}"></script>
   {{-- <script src="{{URL::asset('js/macarons.js')}}"></script>--}}
    <script type="text/javascript">
        var urlArr = [];
        var radarArr = [];
        /*        var chartArr = [];

                window.onresize = function(){
                   for(i=0;i<chartArr.length;i++){
                       chartArr[i].resize();
                   }
                }*/


        function o_window(){
            var request={id:$('#section').attr('report_id')};
            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('/admin/report/export',request,function(e){

            });


            var wi = window.open('about:blank', '_blank');

            wi.document.write(document.getElementById('chart_container').outerHTML);

            var style = wi.document.createElement("style");

            wi.document.getElementById('area-1').value = $('#area-1').val();
            wi.document.getElementById('area-2').value = $('#area-2').val();
            wi.document.getElementById('area-3').value = $('#area-3').val();
            wi.document.getElementById('area-4').value = $('#area-4').val();
            wi.document.getElementById('area-5').value = $('#area-5').val();
            wi.document.getElementById('area-6').value = $('#area-6').val();

            style.innerHTML = 'textarea {\n' +
                'border:0;\n' +
                'overflow:hidden;'
            '}';

            wi.document.body.appendChild(style);
            var listnew = wi.document.getElementsByTagName("canvas");
            var listold = document.getElementsByTagName("canvas");
            for(i=0;i<listold.length;i++){
                var ctx = listold[i].getContext('2d');
                var imgdata = ctx.getImageData(0,0,2500,7500
                );
                var ctxnew = listnew[i].getContext('2d');
                ctxnew.putImageData(imgdata,0,0);
            }
            var div1 = wi.document.getElementById("chart_container");
            /*            div1.style.position = 'fixed';
                        div1.style.top = '0px';
                        div1.style.left = '0px';*/

            wi.opener.export_pdf(div1);
            setTimeout(function(){
                wi.close();
            },1000);
        }

        function export_pdf(div1){
            var contentWidth = 0;
            var contentHeight = 0;
            var w = parseInt(window.getComputedStyle(div1).width);
            var h = parseInt(window.getComputedStyle(div1).height);
            var canvas1 = document.createElement("canvas");
            //canvas1.getContext("2d").translate(20, 0);
            canvas1.getContext("2d").scale(1, 1);
            canvas1.style.width=w+'px';
            canvas1.style.height=h+'px';
            canvas1.width=w;
            canvas1.height=h;

            html2canvas(div1, {canvas:canvas1,allowTaint:true}).then(function(canvas) {
                contentWidth = canvas.width;
                contentHeight = canvas.height;
                //一页pdf显示html页面生成的canvas高度;
                var pageHeight = contentWidth / 592.28 * 841.89;
                //未生成pdf的html页面高度
                var leftHeight = contentHeight;
                //页面偏移
                var position = 0;
                //a4纸的尺寸[595.28,841.89]，html页面生成的canvas在pdf中图片的宽高
                var imgWidth = 595.28;
                var imgHeight = 604.825 / contentWidth * contentHeight;
                //canvas.getContext("2d").translate(-500,-20);
                var pageData = canvas.toDataURL('image/jpeg', 0.95);
                //console.log(pageData);
                //注①
                var pdf = new jsPDF('', 'pt', 'a4');
                //有两个高度需要区分，一个是html页面的实际高度，和生成pdf的页面高度(841.89)
                //当内容未超过pdf一页显示的范围，无需分页
                if (leftHeight < pageHeight) {
                    pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
                } else {
                    while (leftHeight > 0) {
                        //arg3-->距离左边距;arg4-->距离上边距;arg5-->宽度;arg6-->高度
                        pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight)
                        leftHeight -= pageHeight;
                        position -= 841.89;
                        //避免添加空白页
                        if (leftHeight > 100) {
                            //注②
                            pdf.addPage();
                        }
                    }
                }

                var section = $('#section').find("option:selected").text();
                var group = $('#group').find("option:selected").text();
                var squad = $('#squad').find("option:selected").text();
                var student = $('#student').find("option:selected").text();

                var name = section+'-'+group+'-'+squad+'-'+student;
                pdf.save(name+'.pdf');
            });
        }

        $(function(){
            $('#memo').keyup(function(){
                var txtLeng = $('#memo').val().length;
                if( txtLeng>160){//判断字体是否超出界限
//$('.nlzzts').text(' 0 ');
                    var fontsize = $('#memo').val().substring(0,160);
                    $('#memo').val( fontsize );
                }else{
                    $('.nlysrzs').text(txtLeng);//
                    $('.nlzzts').text(160);//剩余文字个数
                }
            });
        });

        $('#btn_save').on('click',function(){
            var request = {};

            request.pid = $('#hid_div').attr('pid');
            request.memo1 = $('#area-1').val();
            request.memo2 = $('#area-2').val();
            request.memo3 = $('#area-3').val();
            request.memo4 = $('#area-4').val();
            request.memo5 = $('#area-5').val();
            request.memo6 = $('#area-6').val();

            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('/admin/report/save_memo',request,function(e){
                alert('保存成功');
            });
        });

        $(document).ready(function(){
            //添加报表
            var chart_type = $('#type').val();

            var data = {};
            data.section=$('#section option:selected').val();
            data.group=$('#group option:selected').val();
            data.squad=$('#squad option:selected').val();
            data.student=$('#student option:selected').val();
            data.startTime=$('#start_time').val();
            data.endTime=$('#end_time').val();

            var student = $('#student').text();
            student = student.split('-');
            /*            var html = '班级：'+$('#squad').text()+'&nbsp;';
                        html += '学号：'+student[0]+'&nbsp;';
                        html += '学生：'+student[1]+'&nbsp;';*/


            var html = '<div>'+student[2]+'</div>';
            html += '<div>'+student[1]+'</div>';
            html += '<div>'+$('#squad').text()+'</div>';
            html += '<div>'+student[0]+'</div>';

            $('#info').append(html);
            $('#info1').append(html);

            chart_type.push(6);
            chart_type.push(7);
            for(t in chart_type){
                data.chart_type = chart_type[t];
                if(chart_type[t] == 1){
                    kaoqin(data);
                }else if(chart_type[t] ==2){
                    tingxie(data);
                }else if(chart_type[t] == 3){
                    ceyan(data);
                }else if(chart_type[t] == 4){
                    jiaxiao(data);
                }else if(chart_type[t] == 5){
                    zuoye(data);
                }else if(chart_type[t] == 6){
                    radar(data);
                }else if(chart_type[t] == 7){
                    memo();
                }else{
                    alert('请选择报表类型');
                    return;
                }
            }

        });


        //听写
        function tingxie(data){
            var myid = 'chart-tingxie';

            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('get_tingxie',data,function(e){
                if(e.status < 0){
                    return -1;
                }else{
                    $('#charts-1').css('display','block');
                    var person = [];
                    var title = [];
                    var class1 = [];

                    var personCount = 0;
                    var classCount = 0;

                    var arr = e.data.person;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        person.push(t.toFixed(2));
                        personCount += parseFloat(arr[x]);
                    }
                    arr = e.data.class;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        class1.push(t.toFixed(2));
                        classCount += parseFloat(arr[x]);
                    }
                    arr = e.data.title;
                    for(x in arr){
                        title.push(arr[x]);
                    }

                    var radar = {};
                    radar.name = '听写';
                    personCount = personCount/person.length;
                    radar.person = personCount.toFixed(2);
                    classCount = classCount/class1.length;
                    radar.squad = classCount.toFixed(2);
                    radarArr.push(radar);


                    var dom1 = document.getElementById(myid);
                    var myChart1 = echarts.init(dom1,'customed');
                    if(class1.length == 1){
                        option = {
                            tooltip: {},
                            title: [{
                                text: '听写成绩',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '15%',
                                textAlign: 'center'
                            }],
                            grid: [{
                                left: '5%',
                                right: '10%',
                                bottom: '5%',
                                containLabel: true
                            }],
                            xAxis: [{
                                type: 'category',
                                data: ['个人成绩','班级平均'],
                                axisLabel: {
                                    interval: 0,
                                    rotate: 30,
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                },
                                splitLine: {
                                    show: false
                                }
                            }],
                            yAxis: [{
                                type: 'value',
                                max: 100,
                                splitLine: {
                                    show: false
                                },
                                axisLabel:{
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                }
                            }],
                            series: [{
                                type: 'bar',
                                stack: 'chart',
                                z: 3,
                                barWidth:60,
                                label: {
                                    normal: {
                                        position: 'top',
                                        show: true,
                                        textStyle : {
                                            fontFamily : '微软雅黑',
                                            fontSize : 15,
                                            fontWeight : 'bolder'
                                        }
                                    }
                                },
                                data: [person[0],class1[0]]
                            }, {
                                type: 'bar',
                                stack: 'chart',
                                silent: true,
                                barWidth:60,
                                itemStyle: {
                                    normal: {
                                        color: '#eee',
                                        fontSize: 10
                                    }
                                },
                                data: [100-person[0],100-class1[0]]
                            }]
                        };
                    }else{
                        option = {
                            title: {
                                text: '听写情况折线图',
                                x:'5%'
                            },
                            tooltip: {
                                trigger: 'axis'
                            },
                            legend: {
                                data:['个人成绩','班级平均'],
                                textStyle: {
                                    fontSize:16
                                },
                                left:'35%'
                            },
                            grid: {
                                left: '5%',
                                right: '10%',
                                containLabel: true
                            },
                            xAxis: {
                                type: 'category',
                                boundaryGap: false,
                                data: title,
                                axisLabel:{
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                }
                            },
                            yAxis: {
                                type: 'value',
                                axisLabel:{
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                }
                            },
                            series: [
                                {
                                    name:'个人成绩',
                                    type:'line',
                                    data:person,
                                    label: {
                                        normal: {
                                            show:true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 18,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    }
                                },
                                {
                                    name:'班级平均',
                                    type:'line',
                                    data:class1,
                                    label: {
                                        normal: {
                                            show:true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 18,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    }
                                }
                            ]
                        };
                    }

                    myChart1.setOption(option);
                }
            });
        }


        //考勤
        function kaoqin(data){
            var myid = 'chart-kaoqin';

            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('get_kaoqin',data,function(e){
                var builderJson = eval('('+e.builderJson+')');
                var personJson = eval('('+e.personJson+')');
                var squadJson = eval('('+e.squadJson+')');
                var sectionJson = eval('('+e.sectionJson+')');
                var memo = e.memo;

                builderJson = JSON.parse(JSON.stringify(builderJson));
                personJson = JSON.parse(JSON.stringify(personJson));
                squadJson = JSON.parse(JSON.stringify(squadJson));
                sectionJson = JSON.parse(JSON.stringify(sectionJson));

                var dom1 = document.getElementById(myid);
                var myChart1 = echarts.init(dom1,'customed');

                /*


                               */


                var radar = {};
                var data = {};
                radar.name = '考勤';
                var personCount = Object.keys(personJson).reduce(function (all, key) {
                    return all + personJson[key];
                }, 0);
                personCount = personJson['正常'] / personCount * 100;
                radar.person = personCount.toFixed(2);
                data.person = personCount.toFixed(2);

                var classCount = Object.keys(squadJson).reduce(function (all, key) {
                    return all + squadJson[key];
                }, 0);
                classCount = squadJson['正常'] / classCount * 100;
                radar.person = personCount.toFixed(2);
                radar.squad = classCount.toFixed(2);
                data.squad = classCount.toFixed(2);

                var sectionCount = Object.keys(sectionJson).reduce(function (all, key) {
                    return all + sectionJson[key];
                }, 0);
                sectionCount = sectionJson['正常'] / sectionCount * 100;
                data.section = sectionCount.toFixed(2);
                radarArr.push(radar);


                var sizeValue='57%';
                option = {
                    legend:{},
                    title: [{
                        text: '个人考勤次数',
                        subtext: '总计 ' + builderJson.all,
                        subtextStyle:{
                            fontSize:18
                        },
                        textStyle:{
                            fontSize:20
                        },
                        x: '25%',
                        y:'10%',
                        textAlign: 'center'
                    }, {
                        text: '出勤率',
                        subtextStyle:{
                            fontSize:18
                        },
                        textStyle:{
                            fontSize:20
                        },
                        x: '75%',
                        y: '10%',
                        textAlign: 'center'
                    }],
                    grid: [
                        {right: sizeValue, bottom: '20%',top:'30%'},
                        {left: sizeValue, bottom: '20%',top:'30%'},
                    ],
                    xAxis: [
                        {gridIndex: 0, axisLabel: {rotate: 50, interval: 0},data: Object.keys(builderJson.charts),},
                        {gridIndex: 1,data: ['个人','班级','班段']},
                    ],
                    yAxis: [
                        {type: 'value', gridIndex: 0},
                        {type: 'value', gridIndex: 1},
                    ],
                    series: [{
                        type: 'bar',
                        z: 3,
                        label: {
                            normal: {
                                position: 'top',
                                show: true,
                                textStyle : {
                                    fontFamily : '微软雅黑',
                                    fontSize : 15,
                                    fontWeight : 'bolder'
                                }
                            }
                        },
                        data: Object.keys(builderJson.charts).map(function (key) {
                            return builderJson.charts[key];
                        })
                    },
                        {
                            type: 'bar',
                            z: 3,
                            label: {
                                normal: {
                                    position: 'top',
                                    show: true,
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 15,
                                        fontWeight : 'bolder'
                                    }
                                }
                            },
                            xAxisIndex:1,
                            yAxisIndex:1,
                            data: Object.keys(data).map(function (key) {
                                return data[key];
                            })
                        },
                    ]
                };

                myChart1.setOption(option);
            });

        }


        //测验
        function ceyan(data){
            var myid = 'chart-ceshi';

            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('get_ceyan',data,function(e){
                if(e.status < 0){
                    return -1;
                }else{
                    var person = [];
                    var title = [];
                    var class1 = [];

                    var personCount = 0;
                    var classCount = 0;

                    var arr = e.data.person;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        person.push(t.toFixed(2));
                        personCount += parseFloat(arr[x]);
                    }
                    arr = e.data.class;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        class1.push(t.toFixed(2));
                        classCount += parseFloat(arr[x]);
                    }
                    arr = e.data.title;
                    for(x in arr){
                        title.push(arr[x].name);
                    }

                    var radar = {};
                    radar.name = '测验';
                    personCount = personCount/person.length;
                    radar.person = personCount.toFixed(2);
                    classCount = classCount/class1.length;
                    radar.squad = classCount.toFixed(2);
                    radarArr.push(radar);

                    var dom1 = document.getElementById(myid);
                    var myChart1 = echarts.init(dom1,'customed');
                    if(class1.length == 1){
                        option = {
                            tooltip: {},
                            title: [{
                                text: '测验成绩',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '15%',
                                textAlign: 'center'
                            }],
                            grid: [{
                                left: '5%',
                                right: '10%',
                                bottom: '5%',
                                containLabel: true
                            }],
                            xAxis: [{
                                type: 'category',
                                data: ['个人成绩','班级平均'],
                                axisLabel: {
                                    interval: 0,
                                    rotate: 30,
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                },
                                splitLine: {
                                    show: false
                                }
                            }],
                            yAxis: [{
                                type: 'value',
                                max: 100,
                                splitLine: {
                                    show: false
                                },
                                axisLabel:{
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                }
                            }],
                            series: [{
                                type: 'bar',
                                stack: 'chart',
                                z: 3,
                                label: {
                                    normal: {
                                        position: 'top',
                                        show: true,
                                        textStyle : {
                                            fontFamily : '微软雅黑',
                                            fontSize : 15,
                                            fontWeight : 'bolder'
                                        }
                                    }
                                },
                                data: [person[0],class1[0]]
                            }, {
                                type: 'bar',
                                stack: 'chart',
                                silent: true,
                                itemStyle: {
                                    normal: {
                                        color: '#eee',
                                        fontSize: 10
                                    }
                                },
                                data: [100-person[0],100-class1[0]]
                            }]
                        };
                    }else{
                        option = {
                            title: {
                                text: '测验情况折线图',
                                x:'5%'
                            },
                            tooltip: {
                                trigger: 'axis'
                            },
                            legend: {
                                data:['个人成绩','班级平均'],
                                textStyle: {
                                    fontSize:16
                                },
                                left:'35%'
                            },
                            grid: {
                                left: '5%',
                                right: '10%',
                                bottom: '5%',
                                containLabel: true
                            },
                            xAxis: {
                                type: 'category',
                                boundaryGap: false,
                                data: title,
                                axisLabel:{
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                }
                            },
                            yAxis: {
                                type: 'value',
                                axisLabel:{
                                    textStyle : {
                                        fontFamily : '微软雅黑',
                                        fontSize : 18
                                    }
                                }
                            },
                            series: [
                                {
                                    name:'个人成绩',
                                    type:'line',
                                    data:person,
                                    label: {
                                        normal: {
                                            show:true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 18,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    },
                                },
                                {
                                    name:'班级平均',
                                    type:'line',
                                    data:class1,
                                    label: {
                                        normal: {
                                            show:true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 18,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    }
                                }
                            ]
                        };
                    }

                    myChart1.setOption(option);
                }
            });
        }

        //家校
        function jiaxiao(data){
            var myid = 'chart-jiaxiao';

            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('get_jiaxiao',data,function(e){
                if(e.status < 0){
                    return -1;
                }else{
                    var jsonData = e.data.data;
                    var personJson = JSON.parse(jsonData.person);
                    var squadJson = JSON.parse(jsonData.class);
                    var sectionJson = JSON.parse(jsonData.section);
                    var memo = e.data.memo;


                    var person = [];
                    var title = [];
                    var class1 = [];

                    var personCount = 0;
                    var classCount = 0;

                    var arr = e.data.score.person;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        person.push(t.toFixed(2));
                        personCount += parseFloat(arr[x]);
                    }
                    arr = e.data.score.class;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        class1.push(t.toFixed(2));
                        classCount += parseFloat(arr[x]);
                    }
                    arr = e.data.title;
                    for(x in arr){
                        title.push(arr[x]);
                    }

                    var radar = {};
                    radar.name = '家校';
                    personCount = personCount/person.length;
                    radar.person = personCount.toFixed(2);
                    classCount = classCount/class1.length;
                    radar.squad = classCount.toFixed(2);
                    radarArr.push(radar);

                    var jx_score_data = {};
                    jx_score_data.person = radar.person;
                    jx_score_data.squad = radar.squad;

                    radar = {};
                    var data = {};
                    radar.name = '家校准交';
                    personCount = 0;
                    personCount = Object.keys(personJson).reduce(function (all, key) {
                        return all + personJson[key];
                    }, 0);
                    personCount = personJson['准交'] / personCount * 100;
                    radar.person = personCount.toFixed(2);
                    data.person = personCount.toFixed(2);

                    classCount=0;
                    classCount = Object.keys(squadJson).reduce(function (all, key) {
                        return all + squadJson[key];
                    }, 0);
                    classCount = squadJson['准交'] / classCount * 100;
                    radar.squad = classCount.toFixed(2);
                    data.squad = classCount.toFixed(2);

                    var sectionCount = Object.keys(sectionJson).reduce(function (all, key) {
                        return all + sectionJson[key];
                    }, 0);
                    sectionCount = sectionJson['准交'] / sectionCount * 100;
                    data.section = sectionCount.toFixed(2);
                    radar.squad = classCount.toFixed(2);
                    radarArr.push(radar);


                    var dom1 = document.getElementById(myid);
                    var myChart1 = echarts.init(dom1,'customed');

                    if(class1.length == 1){
                        var sizeValue='57%';
                        option = {
                            legend:{},
                            title: [{
                                text: '家校分数',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '25%',
                                y:'10%',
                                textAlign: 'center'
                            }, {
                                text: '准交率',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '75%',
                                y: '10%',
                                textAlign: 'center'
                            }],
                            grid: [
                                {right: sizeValue, bottom: '20%',top:'30%'},
                                {left: sizeValue, bottom: '20%',top:'30%'},
                            ],
                            xAxis: [
                                {gridIndex: 0, axisLabel: {rotate: 50, interval: 0},data:['个人成绩','班级平均'],},
                                {gridIndex: 1,data: ['个人','班级','班段']},
                            ],
                            yAxis: [
                                {type: 'value', gridIndex: 0},
                                {type: 'value', gridIndex: 1},
                            ],
                            series: [{
                                type: 'bar',
                                z: 3,
                                label: {
                                    normal: {
                                        position: 'top',
                                        show: true,
                                        textStyle : {
                                            fontFamily : '微软雅黑',
                                            fontSize : 15,
                                            fontWeight : 'bolder'
                                        }
                                    }
                                },
                                data:[jx_score_data.person,jx_score_data.squad]
                            },
                                {
                                    type: 'bar',
                                    z: 3,
                                    label: {
                                        normal: {
                                            position: 'top',
                                            show: true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 15,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    },
                                    xAxisIndex:1,
                                    yAxisIndex:1,
                                    data: Object.keys(data).map(function (key) {
                                        return data[key];
                                    })
                                },
                            ]
                        };
                    }else{
                        var title = [];
                        var sizeValue='57%';
                        for(i=1;i<=class1.length;i++){
                            title.push('第'+i+'次');
                        }
                        option = {
                            legend: {
                                data:['个人成绩','班级平均'],
                                left:'10%',
                                textStyle:{
                                    fontSize:16
                                }
                            },
                            title: [{
                                text: '家校分数',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '25%',
                                y:'10%',
                                textAlign: 'center'
                            }, {
                                text: '准交率',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '75%',
                                y: '10%',
                                textAlign: 'center'
                            }],
                            grid: [
                                {right: sizeValue, bottom: '20%',top:'30%'},
                                {left: sizeValue, bottom: '20%',top:'30%'},
                            ],
                            xAxis: [
                                {gridIndex: 0, axisLabel: {rotate: 50, interval: 0},data:title},
                                {gridIndex: 1,data: ['个人','班级','班段']},
                            ],
                            yAxis: [
                                {type: 'value', gridIndex: 0},
                                {type: 'value', gridIndex: 1},
                            ],
                            series: [                            {
                                name:'个人成绩',
                                type:'line',
                                data:person,
                                label: {
                                    normal: {
                                        show:true,
                                        textStyle : {
                                            fontFamily : '微软雅黑',
                                            fontSize : 18,
                                            fontWeight : 'bolder'
                                        }
                                    }
                                }
                            },
                                {
                                    name:'班级平均',
                                    type:'line',
                                    data:class1,
                                    label: {
                                        normal: {
                                            show:true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 18,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    }
                                },
                                {
                                    type: 'bar',
                                    z: 3,
                                    label: {
                                        normal: {
                                            position: 'top',
                                            show: true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 15,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    },
                                    xAxisIndex:1,
                                    yAxisIndex:1,
                                    data: Object.keys(data).map(function (key) {
                                        return data[key];
                                    })
                                },
                            ]
                        };
                    }

                    myChart1.setOption(option);
                }
            });
        }

        //作业
        function zuoye(data){
            var myid = 'chart-zuoye';

            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('get_zuoye',data,function(e){
                if(e.status < 0){
                    return -1;
                }else{
                    $('#charts-1').css('display','block');
                    var jsonData = e.data.data;
                    var personJson = JSON.parse(jsonData.person);
                    var squadJson = JSON.parse(jsonData.class);
                    var sectionJson = JSON.parse(jsonData.section);
                    var memo = e.data.memo;


                    var person = [];
                    var title = [];
                    var class1 = [];

                    var personCount = 0;
                    var classCount = 0;

                    var arr = e.data.score.person;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        person.push(t.toFixed(2));
                        personCount += parseFloat(arr[x]);
                    }
                    arr = e.data.score.class;
                    for(x in arr){
                        var t = parseFloat(arr[x]);
                        class1.push(t.toFixed(2));
                        classCount += parseFloat(arr[x]);
                    }

                    for(i=1;i<=class1.length;i++){
                        title.push('第'+i+'次');
                    }

                    var radar = {};
                    radar.name = '作业';
                    personCount = personCount/person.length;
                    radar.person = personCount.toFixed(2);
                    classCount = classCount/class1.length;
                    radar.squad = classCount.toFixed(2);
                    radarArr.push(radar);

                    var zy_score_data = {};
                    zy_score_data.person = radar.person;
                    zy_score_data.squad = radar.squad;

                    radar = {};
                    radar.name = '作业准交';
                    personCount = 0;
                    personCount = Object.keys(personJson).reduce(function (all, key) {
                        return all + personJson[key];
                    }, 0);
                    personCount = personJson['准交'] / personCount * 100;
                    radar.person = personCount.toFixed(2);

                    classCount=0;
                    classCount = Object.keys(squadJson).reduce(function (all, key) {
                        return all + squadJson[key];
                    }, 0);
                    classCount = squadJson['准交'] / classCount * 100;
                    radar.person = personCount.toFixed(2);
                    radar.squad = classCount.toFixed(2);
                    radarArr.push(radar);

                    var dom1 = document.getElementById(myid);
                    var myChart1 = echarts.init(dom1,'customed');


                    if(class1.length == 1){
                        var sizeValue='57%';
                        option = {
                            legend:{},
                            title: [{
                                text: '作业分数',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '25%',
                                y:'10%',
                                textAlign: 'center'
                            }, {
                                text: '准交率',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '75%',
                                y: '10%',
                                textAlign: 'center'
                            }],
                            grid: [
                                {right: sizeValue, bottom: '20%',top:'30%'},
                                {left: sizeValue, bottom: '20%',top:'30%'},
                            ],
                            xAxis: [
                                {gridIndex: 0, axisLabel: {rotate: 50, interval: 0},data:['个人成绩','班级平均'],},
                                {gridIndex: 1,data: ['个人','班级']},
                            ],
                            yAxis: [
                                {type: 'value', gridIndex: 0},
                                {type: 'value', gridIndex: 1},
                            ],
                            series: [{
                                type: 'bar',
                                z: 3,
                                label: {
                                    normal: {
                                        position: 'top',
                                        show: true,
                                        textStyle : {
                                            fontFamily : '微软雅黑',
                                            fontSize : 15,
                                            fontWeight : 'bolder'
                                        }
                                    }
                                },
                                data:[zy_score_data.person,zy_score_data.squad]
                            },
                                {
                                    type: 'bar',
                                    z: 3,
                                    label: {
                                        normal: {
                                            position: 'top',
                                            show: true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 15,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    },
                                    xAxisIndex:1,
                                    yAxisIndex:1,
                                    data:[radar.person,radar.squad]
                                },
                            ]
                        };
                    }else{
                        var title = [];
                        var sizeValue='57%';
                        for(i=1;i<=class1.length;i++){
                            title.push('第'+i+'次');
                        }
                        option = {
                            legend: {
                                data:['个人成绩','班级平均'],
                                left:'10%',
                                textStyle:{
                                    fontSize:16
                                }
                            },
                            title: [{
                                text: '作业分数',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '25%',
                                y:'10%',
                                textAlign: 'center'
                            }, {
                                text: '准交率',
                                subtextStyle:{
                                    fontSize:18
                                },
                                textStyle:{
                                    fontSize:20
                                },
                                x: '75%',
                                y: '10%',
                                textAlign: 'center'
                            }],
                            grid: [
                                {right: sizeValue, bottom: '20%',top:'30%'},
                                {left: sizeValue, bottom: '20%',top:'30%'},
                            ],
                            xAxis: [
                                {gridIndex: 0, axisLabel: {rotate: 50, interval: 0},data:title},
                                {gridIndex: 1,data: ['个人','班级']},
                            ],
                            yAxis: [
                                {type: 'value', gridIndex: 0},
                                {type: 'value', gridIndex: 1},
                            ],
                            series: [                            {
                                name:'个人成绩',
                                type:'line',
                                data:person,
                                label: {
                                    normal: {
                                        show:true,
                                        textStyle : {
                                            fontFamily : '微软雅黑',
                                            fontSize : 18,
                                            fontWeight : 'bolder'
                                        }
                                    }
                                }
                            },
                                {
                                    name:'班级平均',
                                    type:'line',
                                    data:class1,
                                    label: {
                                        normal: {
                                            show:true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 18,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    },
                                },
                                {
                                    type: 'bar',
                                    z: 3,
                                    label: {
                                        normal: {
                                            position: 'top',
                                            show: true,
                                            textStyle : {
                                                fontFamily : '微软雅黑',
                                                fontSize : 15,
                                                fontWeight : 'bolder'
                                            }
                                        }
                                    },
                                    xAxisIndex:1,
                                    yAxisIndex:1,
                                    data:[radar.person,radar.squad]
                                },
                            ]
                        };
                    }

                    myChart1.setOption(option);
                }
            });
        }

        //"wow！"图
        //从我的角度我只能做到"哇！为什么我的电脑又死机了！"
        function radar(data){
            var myid = 'chart-radar';

            if(radarArr.length < 3){
                return;
            }
            var dom1 = document.getElementById(myid);
            var myChart1 = echarts.init(dom1,'customed');

            var indicator = [];
            var person =[];
            var squad = [];
            for(i=0;i<radarArr.length;i++){
                var arr = {};
                arr.name = radarArr[i].name;
                arr.max = 100;

                squad.push(radarArr[i].squad);
                person.push(radarArr[i].person);
                indicator.push(arr);
            }

            option = {
                tooltip: {},
                legend: {
                    data: ['个人', '班级'],
                    textStyle: {
                        fontSize:20
                    },
                    x:'70%'
                },
                radar: {
                    // shape: 'circle',
                    name: {
                        textStyle: {
                            color: '#fff',
                            backgroundColor: '#999',
                            borderRadius: 3,
                            padding: [3, 5],
                            fontSize:14
                        }
                    },
                    indicator: indicator
                },
                series: [{
                    type: 'radar',
                    // areaStyle: {normal: {}},
                    data : [
                        {
                            value : squad,
                            name : '班级'
                        },
                        {
                            value : person,
                            name : '个人'
                        }
                    ]
                }]
            };

            myChart1.setOption(option);
        }

        function memo(){
            var request = {pid:$('#hid_div').attr('pid')}
            $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},async:false});
            $.post('get_memo',request,function(e){
                if(e == ''){
                    return;
                }else{
                    var memo = JSON.parse(e);
                    $('#area-1').val(memo.memo1);
                    $('#area-2').val(memo.memo2);
                    $('#area-3').val(memo.memo3);
                    $('#area-4').val(memo.memo4);
                    $('#area-5').val(memo.memo5);
                    $('#area-6').val(memo.memo6);
                }
            });
        }


        function dealImage(base64, w,callback) {
            var newImage = new Image();
            var quality = 1;    //压缩系数0-1之间
            newImage.src = base64;
            newImage.setAttribute("crossOrigin", 'Anonymous');	//url为外域时需要
            var imgWidth, imgHeight;
            newImage.onload = function () {
                imgWidth = this.width;
                imgHeight = this.height;
                var canvas = document.createElement("canvas");
                var ctx = canvas.getContext("2d");
                if (Math.max(imgWidth, imgHeight) > w) {
                    if (imgWidth > imgHeight) {
                        canvas.width = w * 3;
                        canvas.height = w * imgHeight / imgWidth *3;
                    } else {
                        canvas.height = w*3;
                        canvas.width = w * imgWidth / imgHeight *3;
                    }
                } else {
                    canvas.width = imgWidth*3;
                    canvas.height = imgHeight*3;
                    quality = 1;
                }
                ctx.fillStyle = '#fff';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
                var base64_new = canvas.toDataURL("image/jpeg", quality); //压缩语句
                // 如想确保图片压缩到自己想要的尺寸,如要求在50-150kb之间，请加以下语句，quality初始值根据情况自定
                // while (base64.length / 1024 > 150) {
                // 	quality -= 0.01;
                // 	base64 = canvas.toDataURL("image/jpeg", quality);
                // }
                // 防止最后一次压缩低于最低尺寸，只要quality递减合理，无需考虑
                // while (base64.length / 1024 < 50) {
                // 	quality += 0.001;
                // 	base64 = canvas.toDataURL("image/jpeg", quality);
                // }
                callback(base64_new);
            }
        }

        function put_arr(base64){
            urlArr.push(base64);
        }
    </script>
</div>

<div class="box box-body" id="chart_container" style="width:1220px;padding:0 !important;">
    <div class="box box-body" id="charts-0" style="width:1220px;height:1700px;background:url({{URL::asset('images/page1.jpg')}}) no-repeat;background-size:1220px 1700px;margin:0;padding:0;text-align:center;">
        <div id="info" style="width:800px;height:300px;font-size:24px;line-height: 61px;font-weight: bold;position:relative;top:56px;text-align:left;margin-left:180px;"></div>
        <div style="width:1000px;height:300px;margin:auto;margin-top:30px" class="row" id="chart-kaoqin"></div>
        <textarea type="text" style="resize:none;height:100px;width:800px;font-size:18px;" id="area-1"></textarea>
        <div style="width:1000px;height:300px;margin:auto;margin-top:30px" class="row" id="chart-jiaxiao"></div>
        <textarea type="text" style="resize:none;height:100px;width:800px;font-size:18px;" id="area-2"></textarea>
        <div style="width:auto;height:300px;margin:auto;margin-top:30px;overflow:hidden;" class="row">
            <div id="chart-ceshi" style="height:300px;width:460px;margin-left:110px;float:left;padding-left:40px;"></div>
            <div id="chart-radar" style="height:300px;width:500px;margin-right:110px;float:right;"></div>
        </div>
        <textarea type="text" style="margin-right:50px;resize:none;height:100px;font-size:13px;width:340px;overflow:hidden;" id="area-3"></textarea>
        <textarea type="text" id="area-4" style="margin-left:10px;font-size:13px;resize:none;height:100px;width:340px;"/></textarea>
    </div>
    <div class="box box-body" id="charts-1" style="width:1220px;height:1700px;background:url({{URL::asset('images/page1.jpg')}}) no-repeat;background-size:1220px 1700px;margin:0;padding:0;text-align:center;display:none">
        <div id="info1" style="width:800px;height:300px;font-size:24px;line-height: 61px;font-weight: bold;position:relative;top:56px;text-align:left;margin-left:180px;"></div>
        <div style="width:auto;height:400px;margin:auto;margin-top:30px;overflow:hidden;" class="row">
            <div style="width:460px;height:300px;margin-top:50px;margin-left:110px;float:left;padding-left:40px" class="row" id="chart-tingxie"></div>
            <textarea type="text" style="resize:none;margin-top:50px;margin-right:110px;height:250px;width:400px;float:right;font-size:18px;" id="area-5"></textarea>
        </div>
        <div style="width:1000px;height:300px;margin:auto;margin-top:30px" class="row" id="chart-zuoye"></div>
        <textarea type="text" style="resize:none;height:100px;width:800px;font-size:18px;" id="area-6"></textarea>
    </div>
</div>




